#include "SavingsAccount.hh"
#include "IDGenerator.hh"

SavingsAccount::SavingsAccount(Customer* owner) : Account(IDGenerator::generateAccountID(true), owner) {
    // 调用基类构造函数，通过IDGenerator生成账户ID
}

bool SavingsAccount::deposit(double, const string&) {
    cout << "Deposit not allowed on savings account. Use checking account.\n";
    return false;
}

bool SavingsAccount::withdraw(double, const string&) {
    cout << "Withdraw not allowed on savings account. Use checking account.\n";
    return false;
}

bool SavingsAccount::transfer(Account* to, double amount, const string& note) {
    if (!to || amount <= 0) {
        cout << "Invalid transfer parameters.\n";
        return false;
    }

    // Rule: must be same owner, and destination must be a CheckingAccount
    if (to->getOwner() == owner && dynamic_cast<CheckingAccount*>(to)) {
        if (balance >= amount) {
            balance -= amount;
            addTransaction(make_shared<Transaction>("TRANSFER_OUT", amount, this, to, note));
            to->deposit(amount, note);
            return true;
        } else {
            cout << "Insufficient balance.\n";
            return false;
        }
    } else {
        cout << "Savings account can only transfer to your own checking account.\n";
        return false;
    }
}

void SavingsAccount::getInfo() const {
    cout << "Savings Account: " << accountID << " | Balance: ¥" << balance << "\n";
}
string SavingsAccount::getAccountType() const {
    return "Savings Account";
}